/*/////////////////////////////////////////////////////////////////////////////////
/// An
///    ___   ____ ___ _____ ___  ____
///   / _ \ / ___|_ _|_   _/ _ \|  _ \
///  | | | | |  _ | |  | || | | | |_) |
///  | |_| | |_| || |  | || |_| |  _ <
///   \___/ \____|___| |_| \___/|_| \_\
///                              File
///
/// Copyright (c) 2008-2009 Ismail TARIM <ismail@royalspor.com> and the Ogitor Team
//
//This program is free software; you can redistribute it and/or modify it under
//the terms of the GNU Lesser General Public License as published by the Free Software
//Foundation; either version 2 of the License, or (at your option) any later
//version.
//
//This program is distributed in the hope that it will be useful, but WITHOUT
//ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
//FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public License along with
//this program; if not, write to the Free Software Foundation, Inc., 59 Temple
//Place - Suite 330, Boston, MA 02111-1307, USA, or go to
//http://www.gnu.org/copyleft/lesser.txt.
////////////////////////////////////////////////////////////////////////////////*/

#pragma once

namespace Ogitors
{
	/** Enum containing possible Ogitor Menu Widget Types  */
	enum WidgetType
	{
		WIDGET_NONE = 0,		/** Empty(non-existant) widget for base class */
		WIDGET_MENU_ROOT,		/** Root menu widget */
		WIDGET_MENU_ITEM,		/** Menu item widget */
		WIDGET_MENU_SEPARATOR	/** Menu separator widget */
	};

	/// Forward Declarations
	class OGUIEvent;
	class CommandEvent;
	class UpdateEvent;
	class OGUIWidget;
	
	/// A Hash Map to define ID,Widget pairs
	typedef HashMap<int, OGUIWidget *> WidgetMap;
	typedef std::vector<OGUIWidget *> WidgetVector;

	//! Base GUI Widget Class
	/*!  
		A base class for all Ogitor widgets, supplying common functions and virtual function definitions
	*/
	class OgitorExport OGUIWidget
	{
	public:
		/** 
		Constructor 
		*/
		OGUIWidget();
		/** 
		Destructor 
		*/
		virtual ~OGUIWidget();
		/**
		* Returns a pointer to a handle associated with this widget
		* @return
		*/		
		inline void *GetHandle() {return m_Handle;};
		/**
		* Sets new handle for widget
		* @param newHandle a new handle
		*/
		inline void SetHandle(void *newHandle) {m_Handle = newHandle;};
		/**
		* Fetches parent widget
		* @return parent widget
		*/
		inline OGUIWidget *GetParent() {return m_Parent;};
		/**
		* Sets parent for a widget
		* Warning: only used internally
		* @param parent widget
		*/
		inline void SetParent(OGUIWidget *newParent) {m_Parent = newParent;};
		/**
		* Fetches the type of the widget	
		* @return widget type
		*/
		inline WidgetType   GetType() {return m_Type;};
		/**
		* Sets widget type
		* @param new widget type
		*/
		inline void         SetType(WidgetType newType) {m_Type = newType;};
		/**
		* Fetches caption of the widget
		* @return widget caption
		*/
		inline std::string  GetCaption() {return m_Caption;};
		/**
		* Sets widget caption
		* @param new widget caption
		*/
		virtual void        SetCaption(std::string caption) {m_Caption = caption;};
		/**
		* Fetches widget ID
		* @return widget ID
		*/
		inline int          GetID() {return m_ID;};
		/**
		* Sets widget ID
		* @param newID new widget ID
		*/
		inline void         SetID(int newID) {m_ID = newID;};
		/**
		* Fetches widget' 'enabled' flag
		* @return widget' 'enabled' flag
		*/
		inline bool         GetEnabled() { return m_Enabled; };
		/**
		* Sets 'enabled/disabled' flag of the widget 
		* @param enabled new flag setting
		*/
		virtual void        SetEnabled(bool enabled) {m_Enabled = enabled;};
		/**
		* Fetches widget' 'checked' flag
		* @return widget' 'checked' flag
		*/
		inline bool         GetChecked() {return m_Checked;};
		/**
		* Sets 'checked/unchecked' flag of the widget
		* @param checked new flag setting
		*/
		virtual void        SetChecked(bool checked) {m_Checked = checked;};
		/**
		* Fetches widget bitmap' file name
		* @return widget bitmap' file name
		*/
		virtual std::string GetBitmap() { return ""; };
		/**
		* Fetches number of children this widget has (non-recursive)
		* @return number of children (non-recursive)
		*/
		inline int          GetChildCount() {return m_Children.size();};
		/**
		* Fetches widget index
		* @return widget index
		*/
		virtual int         GetIndex() {return -1;};
		/**
		* Fetches widget text
		* @return widget text
		*/
		virtual std::string GetText() {return "";};
		/**
		* Sets widget index
		* @param IDX new widget index
		*/
		virtual void        SetIndex(int IDX) {};
		/**
		* Sets widget text
		* @param text new widget text
		*/
		virtual void        SetText(std::string text) {};
		/**
		* Clears all children of the widget 
		* @param deletechildren flag to DELETE children as well
		*/
		void                Clear(bool deletechildren = true);
		/**
		* Adds a child widget
		* @param widget new child widget
		*/
		void                AddChild(OGUIWidget *widget);
		/**
		* Locate a child by its ID
		* @param ID child' ID
		* @return Widget child if found, 0 if not
		*/
		OGUIWidget         *FindChildByID(int ID);
		/**
		* Fetches ALL children of the widget
		* @return Widget children
		*/
		WidgetVector        GetChildren() {return m_Children;};

	protected:
		void        *m_Handle;	/** Extra data */
		OGUIWidget  *m_Parent;	/** Widget parent */
		WidgetType   m_Type;	/** Widget type enumeration */
		std::string  m_Caption;	/** Widget caption */
		int          m_ID;		/** Widget unique ID */
		bool         m_Enabled;	/** Widget enabled/disabled flag */
		bool         m_Checked;	/** Widget checked/unchecked flag */

		WidgetVector m_Children; /** A list of widget' children */
	};

	//! Menu Widget
	/*!  
		Menu widget to use with mouse right-click
	*/
	class OgitorExport OGUIMenu: public OGUIWidget
	{
	public:
		/**
		* Constructor.
		* @param ID widget unique ID
		* @param Caption menu caption
		* @return bmp16 menu entry icon name
		*/
		OGUIMenu(int ID, std::string Caption, std::string bmp16 = "");
		/** Destructor */
		virtual ~OGUIMenu();
		/**
		* Fetches a icon associated with this widget
		* @return widget icon name
		*/
		virtual std::string GetBitmap() { return m_Bitmap16; }
		/**
		* Adds an entry to menu node
		* @param ID sub-entry unique ID
		* @param Caption sub-entry caption
		* @param bmp16 sub-entry icon name
		* @return newly created sub-entry
		*/
		OGUIMenu *AddItem(int ID, std::string Caption, std::string bmp16 = "");
		/**
		* Adds a separator to menu
		*/
		void      AddSeparator();
	protected:
		std::string m_Bitmap16; /** Name of menu icon */
	};
};
